/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.crossbone.dao;


import com.crossbone.model.User;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author Adem Vural <adem.vural@stud.hs-mannheim.de>
 */
public class UserDao {

    @Resource
    SessionFactory sessionFactory;

    @Transactional(readOnly = true)
    public User getUser(String name) {
        return (User) sessionFactory.getCurrentSession().createCriteria(User.class).add(Restrictions.eq("name", name)).uniqueResult();
    }

    @Transactional
    public void saveUser(User user) {
        sessionFactory.getCurrentSession().save(user);
    }
    
    @Transactional
    public void updateUser(User user){
        sessionFactory.getCurrentSession().update(user);
    }
    
    @Transactional
    public List getUserList(){
        return (List) sessionFactory.getCurrentSession().createCriteria(User.class).add(Restrictions.like("name","adem%")).list();
    }
    
    
}
